import './App.css';
import {Switch, Route, Redirect} from 'react-router-dom'
import { adminRoutes } from './routes';
import Frame from './components/Frame/Index'
import {isLogined} from './utils/auth'

function App() {
  return isLogined()?(
    <Frame>
      <Switch>
        {/* 此处相当于使用了一个for循环将路由从路由组件'./routes/index.js'中取出，并展示在该组件中 */}
      {adminRoutes.map(route=>{
        return (
          <Route key={route.path} path={route.path} exact={route.exact} render={routeProps=>{
            return <route.component {...routeProps}/>
          }}/>
        );
      })}
      <Redirect to={adminRoutes[0].path} from='/admin' />
      <Redirect to="/404" />
      </Switch>
    </Frame>
    ):(
    <Redirect to='/login' />)
}

export default App;
